import java.util.*;
import java.awt.*;


/**
 * <p>Title: PlayerControlsEventLauncher</p>
 * <p>Description: This class is responsible for the "player's event" generation, which
 * events like "press up" or "press down" are included, I mean, events basically related
 * to the spaceship's control.</p>
 * @author Guilherme Mauro Germoglio
 */

public class PlayerControlEventLauncher extends Component {

  private static EventQueue eventQueue;
  private PlayerControlEventListener listener;

  public PlayerControlEventLauncher() {
    this.eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
    enableEvents(0);
  }

  /**
   * Adds a PlayerControlEventListener, what more?
   * @param l The PlayerControlEventListener listener
   */
  public void addPlayerControlEventListener(PlayerControlEventListener l) {
    listener = l;
  }

  /**
   * Maybe puts the event on the event queue, or something like that.
   * @param evt The event will be put on the queue
   */
  public void processEvent(AWTEvent evt) {
    if (evt instanceof PlayerControlEvent) {
      if (listener != null)
        listener.whatThePlayerDid( (PlayerControlEvent) evt);
    }
    else
      super.processEvent(evt);
  }

  /**
   * Launches the event responsible for the start of spaceship's front thruster .
   */
  public void startSpaceshipFrontThruster() {
    SpaceshipFrontThrusterStartEvent sfts = new SpaceshipFrontThrusterStartEvent(this);
    eventQueue.postEvent(sfts);
  }

  /**
   * Launches the event responsible for the stop of spaceship's front thruster.
   */
  public void stopSpaceshipFrontThruster() {
    SpaceshipFrontThrusterStopEvent sfts = new SpaceshipFrontThrusterStopEvent(this);
    eventQueue.postEvent(sfts);
  }

  /**
   * Launches the event responsible for the start of spaceship's rear thruster .
   */
  public void startSpaceshipRearThruster() {
    SpaceshipRearThrusterStartEvent srts = new SpaceshipRearThrusterStartEvent(this);
    eventQueue.postEvent(srts);
  }

  /**
   * Launches the event responsible for the stop of spaceship's rear thruster.
   */
  public void stopSpaceshipRearThruster() {
    SpaceshipRearThrusterStopEvent srts = new SpaceshipRearThrusterStopEvent(this);
    eventQueue.postEvent(srts);
  }

  /**
   * Launches the event responsible for the start of spaceship's turning clockwise movement.
   */
  public void startSpaceshipTurnClockwise() {
    SpaceshipTurnClockWiseStartEvent stcws = new SpaceshipTurnClockWiseStartEvent(this);
    eventQueue.postEvent(stcws);
  }

  /**
   * Launches the event responsible for the stop of spaceship's turning clockwise movement.
   */
  public void stopSpaceshipTurnClockwise() {
    SpaceshipTurnClockWiseStopEvent stcws = new SpaceshipTurnClockWiseStopEvent(this);
    eventQueue.postEvent(stcws);
  }

  /**
   * Launches the event responsible for the start of spaceship's turning counter clockwise movement.
   */
  public void startSpaceshipTurnCounterClockwise() {
    SpaceshipTurnCounterClockWiseStartEvent stccws = new SpaceshipTurnCounterClockWiseStartEvent(this);
    eventQueue.postEvent(stccws);
  }

  /**
   * Launches the event responsible for the stop of spaceship's turning counter clockwise movement.
   */
  public void stopSpaceshipTurnCounterClockwise() {
    SpaceshipTurnCounterClockWiseStopEvent stccws = new SpaceshipTurnCounterClockWiseStopEvent(this);
    eventQueue.postEvent(stccws);
  }

  /**
   * Launches the event responsible for the shoots.
   */
  public void spaceshipShoot() {
    SpaceshipShootEvent ss = new SpaceshipShootEvent(this);
    eventQueue.postEvent(ss);
  }



}



/**
 * <p>Title: PlayerControlEventListener</p>
 * Description: If the player plays, press a key or something like that trying
 * to handle the spaceship, there's an event and there must be something to
 * listen this event, and that's it! The PlayerControlEventListener!
 * @author Guilherme Mauro Germoglio
 */
interface PlayerControlEventListener
    extends EventListener {

  /**
   * Well, someone has to specificate what the player did.
   * @param evt This is it! The event!
   */
  public void whatThePlayerDid(PlayerControlEvent evt);
}

/**
 * <p>Title: PlayerControlEvent</p>
 * <p>Description: This should be what the player did.
 * @author Guilherme Mauro Germoglio
 */

class PlayerControlEvent
    extends AWTEvent {

  // atributes

  public static final int SPACESHIP_FRONT_THRUSTER_START = AWTEvent.RESERVED_ID_MAX + 5561;
  public static final int SPACESHIP_FRONT_THRUSTER_STOP = AWTEvent.RESERVED_ID_MAX + 5562;
  public static final int SPACESHIP_REAR_THRUSTER_START = AWTEvent.RESERVED_ID_MAX + 5563;
  public static final int SPACESHIP_REAR_THRUSTER_STOP = AWTEvent.RESERVED_ID_MAX + 5564;
  public static final int SPACESHIP_TURN_CLOCKWISE_START = AWTEvent.RESERVED_ID_MAX + 5565;
  public static final int SPACESHIP_TURN_CLOCKWISE_STOP = AWTEvent.RESERVED_ID_MAX + 5566;
  public static final int SPACESHIP_TURN_COUNTER_CLOCKWISE_START = AWTEvent.RESERVED_ID_MAX + 5567;
  public static final int SPACESHIP_TURN_COUNTER_CLOCKWISE_STOP = AWTEvent.RESERVED_ID_MAX + 5568;
  public static final int SPACESHIP_SHOOT = AWTEvent.RESERVED_ID_MAX + 5569;
  private int id;

  /**
   * PlayerControlEvent's constructor.
   * @param playerControlsEventLauncher It will be the event source
   * @param id The identity, what more?!
   */
  public PlayerControlEvent(PlayerControlEventLauncher playerControlsEventLauncher, int id) {
    super(playerControlsEventLauncher, id);
  }
}

/**
 * <p>Title: SpaceshipFrontThrusterStartEvent</p>
 * <p>Description: This is the event responsible for the spaceship's front thruster start.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipFrontThrusterStartEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipFrontThrusterStartEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipFrontThrusterStartEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_FRONT_THRUSTER_START);
  }
}

/**
 * <p>Title: SpaceshipFrontThrusterStopEvent</p>
 * <p>Description: This is the event responsible for the spaceship's front thruster stop.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipFrontThrusterStopEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipFrontThrusterStopEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipFrontThrusterStopEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_FRONT_THRUSTER_STOP);
  }
}

/**
 * <p>Title: SpaceshipRearThrusterStartEvent</p>
 * <p>Description: This is the event responsible for the spaceship's rear thruster start.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipRearThrusterStartEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipRearThrusterStartEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipRearThrusterStartEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_REAR_THRUSTER_START);
  }
}

/**
 * <p>Title: SpaceshipRearThrusterStopEvent</p>
 * <p>Description: This is the event responsible for the spaceship's rear thruster stop.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipRearThrusterStopEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipRearThrusterStopEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipRearThrusterStopEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_REAR_THRUSTER_STOP);
  }
}

/**
 * <p>Title: SpaceshipTurnClockWiseStartEvent</p>
 * <p>Description: This is the event responsible for start turning clockwise.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipTurnClockWiseStartEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipTurnClockWiseStartEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipTurnClockWiseStartEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_TURN_CLOCKWISE_START);
  }
}

/**
 * <p>Title: SpaceshipTurnClockWiseStopEvent</p>
 * <p>Description: This is the event responsible for stop turning clockwise.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipTurnClockWiseStopEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipTurnClockWiseStopEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipTurnClockWiseStopEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_TURN_CLOCKWISE_STOP);
  }
}

/**
 * <p>Title: SpaceshipTurnCounterClockWiseStartEvent</p>
 * <p>Description: This is the event responsible for start turning counter clockwise.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipTurnCounterClockWiseStartEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipTurnCounterClockWiseStartEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipTurnCounterClockWiseStartEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_TURN_COUNTER_CLOCKWISE_START);
  }
}

/**
 * <p>Title: SpaceshipTurnCounterClockWiseStopEvent</p>
 * <p>Description: This is the event responsible for stop turning counter clockwise.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipTurnCounterClockWiseStopEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipTurnCounterClockWiseStopEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipTurnCounterClockWiseStopEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_TURN_COUNTER_CLOCKWISE_STOP);
  }
}

/**
 * <p>Title: SpaceshipShootEvent</p>
 * <p>Description: This is the event responsible for all the chaos - the shooting.
 * @author Guilherme Mauro Germoglio
 */
class SpaceshipShootEvent
    extends PlayerControlEvent {

  /**
   * SpaceshipShootEvent's contructor
   * @param playerControlEventLauncher The event's source.
   */
  public SpaceshipShootEvent(PlayerControlEventLauncher playerControlEventLauncher) {
    super(playerControlEventLauncher, PlayerControlEvent.SPACESHIP_SHOOT);
  }
}


